<template>
	<view>
		<a-skeleton active :loading="detail=={}">
		</a-skeleton>
		<view class="article-rich-text-box">
			<a-typography-title style="text-align: center;">{{detail.title}}</a-typography-title>
			<view class="article-time">
				<uni-dateformat :date="detail.publish_date" :threshold="[0,0]">
				</uni-dateformat>
			</view>
			<view class="article-rich-text">
				<rich-text style="padding-left: 10%;padding-right: 10%" :nodes="detail.content"></rich-text>
			</view>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	const cmd = db.command
	export default {
		data() {
			return {
				id: '',
				detail: {}
			}
		},
		onLoad(options) {

			if (options.id) {
				this.id = options.id
			}
		},
		onReady() {
			this.getDetailAtricle()
		},
		methods: {
			async getDetailAtricle() {
				const detatil = await db.collection('news-articles')
					.where({
						_id: this.id
					}).limit(1).get()
				if (detatil.result.data.length > 0) {
					this.detail = detatil.result.data[0]
				}
			}
		}
	}
</script>

<style>
	@import url('./detail.css');
</style>
